package com.zgscwjm.taobaphelper;

import android.content.Context;
import android.net.ConnectivityManager;
import android.util.Log;

import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 基本配置类 ---对应原 v.class
 * Created by zgscwjm on 17-2-27.
 */
public final class BaseConfig {
    //这里应该就是url
    public static String baseUrl;

    
    //// FIXME: 17-2-27 这些都应该是网络接口地址
    public static final String b = (baseUrl+"");
    public static final String c = (baseUrl+"");
    public static final String d = (baseUrl+"");;
    public static final String e= (baseUrl+"");;
    public static final String f= (baseUrl+"");;
    public static final String g= (baseUrl+"");;
    public static final String h= (baseUrl+"");;
    public static final String i= (baseUrl+"");;
    public static final String j= (baseUrl+"");;
    public static final String k= (baseUrl+"");;
    public static final String l= (baseUrl+"");;
    public static final String m= (baseUrl+"");;
    public static final String n= (baseUrl+"");;



    public static String a(final String url,final Context context){
        return a(url,null,context);
    }
    public static String a(final String url, final Map map, final Context context){
        final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(context.CONNECTIVITY_SERVICE);
        if (connectivityManager.getActiveNetworkInfo()==null || !connectivityManager.getActiveNetworkInfo().isAvailable()) {
            return "";
        }

        //实例化一个线程池
        final ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
        final RequestBean requestBean = new RequestBean(url,map,context);
        try{
            final String string = cachedThreadPool.submit((Callable<Object>) requestBean).get().toString();
            Log.i("result","result:"+string);
            return string;
        }catch (Exception ex){
            return "";
        }finally {
            if (cachedThreadPool!=null){
                cachedThreadPool.shutdown();
            }
        }
    }


    /**
     * 这个是检查网络
     * 可以替换上面的a方法
     * 替换成了checknet 原本叫a
     * @param context
     * @return
     */
    public static boolean checknet(final Context context){
        final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        return connectivityManager.getActiveNetworkInfo() !=null && connectivityManager.getActiveNetworkInfo().isAvailable();
    }
}
